<?php
require_once dirname(__FILE__) . '/../config/config.php';
class TelcoPromotionController
{
    private $smarty;
    public function __construct()
    {
    }

    public function main(&$smarty)
    {
        $this->smarty = $smarty;
    }

    public function listAction()
    {
        $context = new BaseContext();
        $result = new ServiceResult();
        $telcoPromotionService = new TelcoPromotionService(); 
        $telcoPromotionArr = $telcoPromotionService -> getTelcoPromotion($context, $result);
        $this->smarty->assign('telcoPromotionArr', $telcoPromotionArr);
        
        $this->smarty->display('list-telco-promotion.tpl');
    }

    public function addAction()
    {
        $_SESSION['timeout'] = time();
        $context = new BaseContext();
        $result = new ServiceResult();
		$telcoPromotionService = new TelcoPromotionService();
		
    	if(isset($_POST) && !empty($_POST))
        {
        
            $_POST['detail'] = stripslashes($_POST['detail']);
            $param = $_POST;
            $telcoPromotionService->insertTelcoPromotion($context, $result, $param);
            header("location:".WEB_BASE_URL."/index.php?controller=telcoPromotion&action=list");
        }
        else
        {
            $this->smarty->display('add-telco-promotion.php');
        }    
    }
    
	public function deleteAction()
    {
        $_SESSION['timeout'] = time();
    	if(isset($_GET['id']) && !empty($_GET['id']))
		{
		  	$id = $_GET['id'];
		}
        $context = new BaseContext();
        $result = new ServiceResult();
       	$telcoPromotionService = new TelcoPromotionService();
        
        $telcoPromotionService->deleteTelcoPromotion($context, $result, $id);

        header("location:".WEB_BASE_URL."/index.php?controller=telcoPromotion&action=list");
    }

}

?>